﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Win32;

namespace CLFramework.EnvironmentCheck.CheckItems
{
    public class NetFX35 : ICheckItem
    {
        public string Name
        {
            get { return "微软 .NET Framework 3.5"; }
        }

        public string Remarks
        {
            get
            {
                bool ok = result;
                if (!check)
                {
                    ok = Result;
                }

                if (ok)
                    return "已安装版本" + clr;
                else
                    return "请安装微软.NET Framework 3.5运行环境";
            }
        }

        public bool Must
        {
            get
            {
                return true;
            }
        }

        private bool result = false;
        private bool check = false;
        private string clr = string.Empty;
        public bool Result
        {
            get
            {
                if (!check)
                {
                    result = IsRegeditKeyExit();
                }
                return result;
            }
        }

        public int Order
        {
            get { return 1; }
        }

        private bool IsRegeditKeyExit()
        {
            RegistryKey subKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\5.0\User Agent\Post Platform");
            string[] keyNames = subKey.GetValueNames();
            subKey.Close();
            bool result = false;
            foreach (string keyName in keyNames)
            {
                if (keyName.StartsWith(".NET CLR 3.5"))
                {
                    result = true;
                    clr = keyName;
                    break;
                }
            }

            return result;
        }
    }
}
